/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PurchaseDetails2.java
 *
 * Created on Dec 14, 2009, 2:52:09 PM
 */

package GUI;

import Business.Purchase_BS;
import Business.SupplierProcess_BS;
import Business.Supplier_BS;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author anhvtn_b00545
 */
public class PurchaseDetails2 extends javax.swing.JDialog {
    private int pcId;
    private PurchaseDetailsTableModel detailsTableModel;
    private Purchase_BS purchase;
    SupplierProcess_BS supplierBO = new SupplierProcess_BS();
    /** Creates new form PurchaseDetails2 */
    public PurchaseDetails2(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        Vector<Supplier_BS> suppliers = new Vector<Supplier_BS>(supplierBO.getAllSupplier());
        cbxSupplier.setModel(new DefaultComboBoxModel(suppliers));
    }

    public void setPurchaseId(int pcId) {
        this.pcId = pcId;
    }
     public void setPurchase(Purchase_BS purchase) {
        //this.pcId = pcId;

        lblDatePaid.setText(purchase.getPcDate());
        cbxSupplier.setSelectedItem(purchase.getSName());
        txtPaid.setText(String.valueOf(purchase.getPaid()));
        txtUnpaid.setText(String.valueOf(purchase.getUnpaid()));
       // System.out.println(purchase.getSName());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btClose = new javax.swing.JButton();
        lblCode1 = new javax.swing.JLabel();
        cbxSupplier = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPurchaseDetails = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        lblPaid = new javax.swing.JLabel();
        txtPay = new javax.swing.JTextField();
        btPay = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtBalance = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        lblTotal = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtPaid = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtUnpaid = new javax.swing.JLabel();
        lblbDate = new javax.swing.JLabel();
        lblDatePaid = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Purchase Details", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Monotype Corsiva", 1, 36), new java.awt.Color(51, 102, 0))); // NOI18N

        btClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Img/No.png"))); // NOI18N
        btClose.setText("Close");
        btClose.setActionCommand("buttton1");
        btClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCloseActionPerformed(evt);
            }
        });

        lblCode1.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblCode1.setText("Supplier ");

        cbxSupplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxSupplierActionPerformed(evt);
            }
        });

        tblPurchaseDetails.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblPurchaseDetails.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblPurchaseDetailsMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblPurchaseDetails);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Pay"));

        lblPaid.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblPaid.setText("Pay : ");

        txtPay.setText("0");

        btPay.setText("Pay");
        btPay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPayActionPerformed(evt);
            }
        });

        jLabel2.setText("VND");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("Balance : ");

        txtBalance.setText("0");

        jLabel4.setText("VND");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Total : ");

        lblTotal.setText("0");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setText("Paid : ");

        txtPaid.setText("0");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel6.setText("Unpaid: ");

        txtUnpaid.setText("0");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(lblPaid)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPay, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 201, Short.MAX_VALUE)
                        .addComponent(btPay))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPaid, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)))
                .addGap(58, 58, 58)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBalance, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtUnpaid, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(78, 78, 78))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblTotal)
                    .addComponent(jLabel5)
                    .addComponent(txtPaid)
                    .addComponent(jLabel6)
                    .addComponent(txtUnpaid))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblPaid)
                        .addComponent(jLabel3)
                        .addComponent(txtBalance)
                        .addComponent(jLabel4))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtPay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(btPay)))
                .addContainerGap())
        );

        lblbDate.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblbDate.setText("Date Paid : ");

        lblDatePaid.setText("date");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblbDate)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblDatePaid, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(377, 377, 377))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(lblCode1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbxSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(639, 639, 639))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(455, Short.MAX_VALUE)
                .addComponent(btClose, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(333, 333, 333))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 794, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblbDate)
                    .addComponent(lblDatePaid))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCode1)
                    .addComponent(cbxSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btClose))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 812, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCloseActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_btCloseActionPerformed

    private void tblPurchaseDetailsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPurchaseDetailsMouseClicked

        if (evt.getClickCount() > 1) {
            int row = tblPurchaseDetails.getSelectedRow();
            //            PurchaseDetails_BS selectedPurchase = getProductPurchaseAtRow(row);
        }
}//GEN-LAST:event_tblPurchaseDetailsMouseClicked

    private void cbxSupplierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxSupplierActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cbxSupplierActionPerformed

    private void btPayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPayActionPerformed
        // TODO add your handling code here:
        //        Float paid = Float.valueOf(txtPaid.getText()).floatValue();
        //        float totalPrice= ps.getTotal();
        //        float unpaid= Float.valueOf(txtUnpaid.getText().trim()).floatValue();
        //        float pay = Float.valueOf(txtPay.getText().trim()).floatValue();
        //        float balance = Float.valueOf(txtBalance.getText().trim()).floatValue();
        //
        //        if(pay !=0) {
        //            if(pay > unpaid) {
        //                JOptionPane.showMessageDialog(this,"Pay not more than Unpaid!","Error",JOptionPane.ERROR_MESSAGE);
        //            } else{
        //                unpaid = unpaid - pay;
        //                balance = unpaid - pay;
        //                paid += pay ;
        //                ps.setPaid(paid);
        //                ps.setUnpaid(unpaid);
        //                txtPaid.setText(String.valueOf(ps.getPaid()));
        //                txtUnpaid.setText(String.valueOf(ps.getUnpaid()));
        //            }
        //        } else {
        //            balance= unpaid;
        //            ps.setPaid(paid);
        //            ps.setUnpaid(unpaid);
        //        }
        //
        //        txtBalance.setText(String.valueOf(unpaid));
}//GEN-LAST:event_btPayActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btClose;
    private javax.swing.JButton btPay;
    private javax.swing.JComboBox cbxSupplier;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblCode1;
    private javax.swing.JLabel lblDatePaid;
    private javax.swing.JLabel lblPaid;
    private javax.swing.JLabel lblTotal;
    private javax.swing.JLabel lblbDate;
    private javax.swing.JTable tblPurchaseDetails;
    private javax.swing.JLabel txtBalance;
    private javax.swing.JLabel txtPaid;
    private javax.swing.JTextField txtPay;
    private javax.swing.JLabel txtUnpaid;
    // End of variables declaration//GEN-END:variables

}
